package sh.ds.el.entity.base;

import java.io.Serializable;

@SuppressWarnings("serial")
public abstract class BaseEntity implements Serializable, Idable {

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		
		if (!getClass().equals(obj.getClass())) {
			return false;
		}
		
		if (this == obj) {
			return true;
		}
		
		Serializable id = this.getId();
		Serializable otherId = ((BaseEntity) obj).getId();
		if (id == null && otherId == null) {
			return true;
		}
		if (id == null || otherId == null) {
			return false;
		}
		return id.equals(otherId);
	}
	
	@Override
	public int hashCode() {
		int hashCode = 13;
		hashCode = hashCode + (getId() == null ? 0 : getId().hashCode());
		return hashCode;
	}
	
	@Override
	public String toString() {
		return getClass() + "[id=" + getId() + "]";
	}
	
}
